<template>
    <div>
        <h1>会员等级增加页面</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">等级名称</td>
                    <td><input type="text" v-model="queryInfo.LevelName"></td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="增加" @click="addlevel">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';
import axios from 'axios';
import { ref,reactive } from 'vue'

//获取路由对象
const router = useRouter();
//声明后端所需要的数据

let queryInfo = reactive({
    LevelName:''
})

const addlevel = () => {
    if(queryInfo.LevelName == '')
    {
        alert('等级名称不能为空');
        return;
    }
    axios({
        url:'/api/Member/AddMemberLevel',
        method:'post',
        data:queryInfo
    })
    .then((res)=>{
        if(res.data == -1)
        {
            alert('该名称已存在');
            return;
        }
        if(res.data == -2)
        {
            alert('添加失败');
            return;
        }
        if(res.data == 1)
        {
            alert('添加成功');
            router.push('/memberlevellist');
        }
    })
    .then((err)=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>